home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / e / gencodee_v21.lha / GenCodeE / E / Localized_DemoGenCodeE21b / DemoGenCodeE.e < prev    next >
Text File  |  1994-11-15  |  8KB  |  222 lines

  1. OPT OSVERSION = 37
  2. OPT TURBO
  3.  
  4.  
  5. /* ////////////////////////////////////////////////////////////////////////////
  6. //////////////////////////////////////////////////////// External modules /////
  7. //////////////////////////////////////////////////////////////////////////// */
  8. MODULE 'locale'
  9. MODULE 'icon'
  10.  
  11. PMODULE 'GUI'
  12. PMODULE 'Locale'
  13.  
  14.  
  15. /* ////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////////////////////////////// Exception handling /////
  17. //////////////////////////////////////////////////////////////////////////// */
  18. RAISE    "MEM"    IF    New()    =    NIL
  19.  
  20.  
  21. /* ////////////////////////////////////////////////////////////////////////////
  22. //////////////////////////////////////////////////////// Global variables /////
  23. //////////////////////////////////////////////////////////////////////////// */
  24. DEF dgce    :    PTR TO app_obj    /* look at GUI.e for "app_obj" object */
  25. DEF string_var    :    PTR TO CHAR    /* used by a notification (see GUI.e line 154) */
  26.  
  27.  
  28. /* ////////////////////////////////////////////////////////////////////////////
  29. ////////////////////////////////////////////////////////// Main Procedure /////
  30. //////////////////////////////////////////////////////////////////////////// */
  31. PROC main() HANDLE
  32.  
  33.     DEF running = TRUE , result_domethod , signal , mui_error
  34.     DEF arexx : app_arexx , display : app_display
  35.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  36.     DEF icon = NIL
  37.  
  38.         /* localization init */
  39.     localebase := OpenLibrary( 'locale.library' , 0 )
  40.     open_DemoGenCodeE_catalog( NIL , NIL )    /* see Locale.e */
  41.  
  42.         /* needed libraries and icon init */
  43.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Raise( "muim" )
  44.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Raise( "icon" )
  45.  
  46.         /* exported variables init */
  47.     string_var := get_DemoGenCodeE_string( msg_String_Variable_Put )
  48.  
  49.         /* MUI GUI init */
  50.             /* in GUI.e line 17, you can see the declaration of "app_display" object */
  51.             /* each field of this object correspond to a hook function declared in MUIBuilder */
  52.             /* in the present case, there is only the "button_pressed" hook function (see GUI.e line 166) */
  53.     installhook( display.button_pressed , {button_pressed} )
  54.  
  55.         /* ARexx init */
  56.             /* for ARexx init you must fill an "app_arexx" object defined in GUI.e line 12 */
  57.             /* this object gets 2 fields : one for the commands and one for the arexx error hook function */
  58.     installhook( change_text_hook , {change_text} )
  59.     arexx.commands := ( arexx_commands := New( ( SIZEOF mui_command ) * 2 ) )
  60.     arexx_commands[].mc_name := 'change_text'
  61.     arexx_commands[].mc_template := ''
  62.     arexx_commands[].mc_parameters := 0
  63.     arexx_commands[].mc_hook := change_text_hook
  64.     installhook( arexx.error , {arexx_error} )
  65.  
  66.         /* MUI application creation */
  67.             /* for this you call the create method (see GUI.e line 43) on the "app_obj" object */
  68.             /* to this method, you must give the "app_display" object */
  69.             /* and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete) */
  70.     IF ( dgce := create_app( display , icon , arexx , NIL ) ) = NIL THEN Raise( "MUI" )
  71.     init_notifications_app( dgce , display )
  72.  
  73.         /* Main loop */
  74.     WHILE running
  75.  
  76.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  77.         SELECT result_domethod
  78.  
  79.             CASE ID_BUTTON_PRESSED    /* see GUI.em line 37 for the definition of this ID */
  80.  
  81.                 set( dgce.tx_result , MUIA_Text_Contents , get_DemoGenCodeE_string( msg_Modified_ID_Returned ) )
  82.  
  83.             CASE MUIV_Application_ReturnID_Quit
  84.  
  85.                 running := FALSE
  86.  
  87.         ENDSELECT
  88.  
  89.         IF ( signal AND running ) THEN Wait( signal )
  90.  
  91.     ENDWHILE
  92.  
  93.     dispose_app( dgce )
  94.     IF icon            THEN FreeDiskObject( icon )
  95.     IF iconbase        THEN CloseLibrary( iconbase )
  96.     CloseLibrary( muimasterbase )
  97.     close_DemoGenCodeE_catalog()
  98.     IF localebase        THEN CloseLibrary( localebase )
  99.  
  100. EXCEPT
  101.  
  102.     SELECT exception
  103.  
  104.         CASE "muim"
  105.  
  106.             error_simple( get_DemoGenCodeE_string( msg_Missing_Muimaster_Library ) )
  107.  
  108.         CASE "icon"
  109.  
  110.             error_simple( get_DemoGenCodeE_string( msg_Missing_Icon_Library ) )
  111.  
  112.         CASE "MEM"
  113.  
  114.             error( get_DemoGenCodeE_string( msg_Not_Enough_Memory ) )
  115.  
  116.         CASE "MUI"
  117.  
  118.             mui_error := Mui_Error()
  119.  
  120.             SELECT mui_error
  121.  
  122.                 CASE MUIE_OutOfMemory
  123.  
  124.                     error_simple( get_DemoGenCodeE_string( msg_Not_Enough_Memory ) )
  125.  
  126.                 CASE MUIE_OutOfGfxMemory
  127.  
  128.                     error_simple( get_DemoGenCodeE_string( msg_Not_Enough_Chip_Memory ) )
  129.  
  130.                 CASE MUIE_MissingLibrary
  131.  
  132.                     error_simple( get_DemoGenCodeE_string( msg_Missing_Library ) )
  133.  
  134.                 CASE MUIE_NoARexx
  135.  
  136.                     error_simple( get_DemoGenCodeE_string( msg_Arexx_Port ) )
  137.  
  138.                 DEFAULT
  139.  
  140.                     error_simple( get_DemoGenCodeE_string( msg_Internal_Problem ) )
  141.  
  142.             ENDSELECT
  143.  
  144.     ENDSELECT
  145.  
  146.     IF dgce            THEN dispose_app( dgce )
  147.     IF icon            THEN FreeDiskObject( icon )
  148.     IF iconbase        THEN CloseLibrary( iconbase )
  149.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  150.     close_DemoGenCodeE_catalog()
  151.     IF localebase        THEN CloseLibrary( localebase )
  152.  
  153. ENDPROC
  154.  
  155.  
  156. /* ////////////////////////////////////////////////////////////////////////////
  157. ///////////////////// Prints an error message with an intuition requester /////
  158. //////////////////////////////////////////////////////////////////////////// */
  159. PROC error_simple( message : PTR TO CHAR ) RETURN EasyRequestArgs(    NIL , [ 20 , 0 ,
  160.                                     get_DemoGenCodeE_string( msg_DGCE_Error ) ,
  161.                                     message ,
  162.                                     get_DemoGenCodeE_string( msg_Simple_OK ) ] , NIL , NIL )
  163.  
  164.  
  165. /* ////////////////////////////////////////////////////////////////////////////
  166. /////////////////////////// Prints an error message with an MUI requester /////
  167. //////////////////////////////////////////////////////////////////////////// */
  168. PROC error( message : PTR TO CHAR ) RETURN Mui_RequestA(    dgce.app ,
  169.                                 dgce.wi_the_window ,
  170.                                 NIL ,
  171.                                 get_DemoGenCodeE_string( msg_DGCE_Error ) ,
  172.                                 get_DemoGenCodeE_string( msg_OK ) ,
  173.                                 message ,
  174.                                 NIL )
  175.  
  176.  
  177. /* ////////////////////////////////////////////////////////////////////////////
  178. /////////// Hook function called each time bt_call_hook button is pressed /////
  179. //////////////////////////////////////////////////////////////////////////// */
  180. PROC button_pressed( hook , obj , msg ) RETURN set( dgce.tx_result , MUIA_Text_Contents , get_DemoGenCodeE_string( msg_Modified_By_Hook ) )
  181.  
  182.  
  183. /* ////////////////////////////////////////////////////////////////////////////
  184. /////////////////////// Hook function called by ARexx command change_text /////
  185. //////////////////////////////////////////////////////////////////////////// */
  186. PROC change_text( hook , obj , msg ) RETURN set( dgce.tx_result , MUIA_Text_Contents , get_DemoGenCodeE_string( msg_Modified_By_Arexx ) )
  187.  
  188.  
  189. /* ////////////////////////////////////////////////////////////////////////////
  190. ////////////////////////// Hook function called by ARexx in case of error /////
  191. //////////////////////////////////////////////////////////////////////////// */
  192. PROC arexx_error( hook , obj , msg ) RETURN error_simple( get_DemoGenCodeE_string( msg_Unknown_ARexx_Command ) )
  193.  
  194.  
  195. /* ////////////////////////////////////////////////////////////////////////////
  196. ///////////////////////// Directly taken from the Amiga v3.0 distribution /////
  197. //////////////////////////////////////////////////////////////////////////// */
  198. PROC installhook(hook,func)
  199.  
  200.     DEF return
  201.  
  202.     MOVE.L    hook,A0
  203.     MOVE.L    func,12(A0)
  204.     LEA    hookentry(PC),A1
  205.     MOVE.L    A1,8(A0)
  206.     MOVE.L    A4,16(A0)
  207.     MOVE.L    A0,return
  208.  
  209. ENDPROC return
  210.  
  211. hookentry:
  212.     MOVEM.L    D2-D7/A2-A6,-(A7)
  213.     MOVE.L    16(A0),A4
  214.     MOVE.L    A0,-(A7)
  215.     MOVE.L    A2,-(A7)
  216.     MOVE.L    A1,-(A7)
  217.     MOVE.L    12(A0),A0
  218.     JSR    (A0)
  219.     LEA    12(A7),A7
  220.     MOVEM.L    (A7)+,D2-D7/A2-A6
  221.     RTS
  222.